package com.surge;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SurgeMain {

	private static ApplicationContext ctx;

	public static void main(String[] args) {
		
		
		// 创建 Spring 的 IOC 容器
		ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		
		/*
		 * 1、作用域singleton
		 */
		Address address =  (Address) ctx.getBean("address");
		Address address2 =  (Address) ctx.getBean("address");
		// 作用域为 singleton时，判断是不是同一个bean，及是否为单例
		System.out.println(address == address2);

		
		System.out.println("============== demo 分隔符 =============");
		
		
		/*
		 * 2、作用域prototype 创建空构造方法。查看对象实例化时间
		 */
		// 屏蔽/打开下面实例化代码，看address是否创建。 或加断点调试，查看address创建时间
		Address address3 =  (Address) ctx.getBean("address3");
		Address address4 =  (Address) ctx.getBean("address3");
		System.out.println(address3 == address4);
	}

}
